﻿@using XRM.Security.WebUI.Consts
@model XRM.Security.WebUI.Models.SystemUser.SystemUserModel
@{
    ViewBag.Title = Model.IsEdit ? Model.FullName : "Добавление сотрудника";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@Html.Partial("ReturnLinkPartial", new Tuple<string, string>(Url.Action("Index"), "Вернуться к списку системных пользователей"))
<div>
    @using (Html.BeginForm("Edit", "SystemUser", FormMethod.Post, new {@class = "form-horizontal"}))
    {
        @Html.AntiForgeryToken()

        const string inputCss = "form-control";

        @Html.HiddenFor(m => m.Id)
        @Html.HiddenFor(m => m.Login)

        <div class="form-group">
            @Html.LabelFor(m => m.LastName, new { @class = "control-label required" })
            <div class="col-sm-3">
                @Html.TextBoxFor(m => m.LastName, new { @class = @inputCss })
                @Html.ValidationMessageFor(m => m.LastName)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.FirstName, new { @class = "control-label required" })
            <div class="col-sm-3">
                @Html.TextBoxFor(m => m.FirstName, new { @class = @inputCss })
                @Html.ValidationMessageFor(m => m.FirstName)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.MotherName, new { @class = "control-label" })
            <div class="col-sm-3">
                @Html.TextBoxFor(m => m.MotherName, new { @class = @inputCss })
                @Html.ValidationMessageFor(m => m.MotherName)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.Login, new { @class = "control-label required" })
            <div class="col-sm-3">
                @Html.TextBoxFor(m => m.Login, new { @class = @inputCss, disabled = "disabled" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.Post, new { @class = "control-label required" })
            <div class="col-sm-3">
                @Html.TextBoxFor(m => m.Post, new { @class = @inputCss })
                @Html.ValidationMessageFor(m => m.Post)
            </div>
        </div>
    
        <div class="form-group">
            @Html.LabelFor(m => m.Roles, new { @class = "control-label" })
            <div class="col-sm-5">
                @foreach (var item in Model.AllRoles)
                {
                    <div class="checkbox">
                        <label for="@item.RoleName">
                            <input type="checkbox" name="RolesCheck" value="@item.RoleName" id="@item.RoleName"
                                @if (Model.Roles.Where(x=>x.RoleName.Equals(item.RoleName)).Any()) 
                                { 
                                    <text> checked='checked' </text>   
                                } />
                            @item.Description
                        </label>
                    </div>
                }
            </div>
        </div>
        @Html.Partial("_FormActionsPartial", new ViewDataDictionary{{ViewDataConsts.ReturnUrl, Url.Action("Index")}})
    }
</div>